/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package login;

import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import login.vista.FailLoginController;
import login.vista.LoginController;
import login.vista.SuccessLoginController;

/**
 *
 * @author nahe
 */
public class LoginHostal extends Application {
    
    private Stage mainStage;
    
    public void start(Stage stage) throws Exception {
        try{
                    
            mainStage= stage;
            loadLoginScene();
            mainStage.show();  
        } catch(Exception ex){
            Logger.getLogger(LoginHostal.class.getName()).log(Level.SEVERE, null, ex);
        }
     
//        Parent root = FXMLLoader.load(getClass().getResource("vista/Login.fxml"));
//        
//        Scene scene = new Scene(root);
//        
//        stage.setScene(scene);
//        stage.show();
  }   
    
    public void loadLoginScene() {
        try{
            LoginController login=(LoginController) replaceSceneContent("vista/Login.fxml");
            login.setApp(this);
        }catch (Exception ex){
            Logger.getLogger(LoginHostal.class.getName()).log(Level.SEVERE, null, ex);
        }   
    }
    
    public void loadSuccessLoginScene() {
        try{
            SuccessLoginController success=(SuccessLoginController) replaceSceneContent("vista/SuccessLogin.fxml");
            success.setApp(this);
        }catch (Exception ex){
            Logger.getLogger(LoginHostal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void loadFailLoginScene() {
        try{
            FailLoginController fail=(FailLoginController) replaceSceneContent("vista/FailLogin.fxml");
            fail.setApp(this);
        }catch (Exception ex){
            Logger.getLogger(LoginHostal.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }



    
    private Initializable replaceSceneContent(String fxml) throws Exception{
        FXMLLoader loader = new FXMLLoader();
        InputStream in = LoginHostal.class.getResourceAsStream(fxml);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(LoginHostal.class.getResource(fxml));
        AnchorPane page;
        try{
            page=(AnchorPane)loader.load(in);
        }finally{
            in.close();
        }
        
        Scene scene= new Scene(page);
        
        mainStage.setScene(scene);
        
        mainStage.sizeToScene();
        
        return(Initializable) loader.getController(); 
   }
    public static void main(String[] args) {
        launch(args);
    }



}